package com.handwriting.backend.utils;

import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class JsonUtils {
    private final Gson gson;

    @Autowired
    public JsonUtils() {
        this.gson = new Gson();
    }

    public String toJson(Object o) {
        return gson.toJson(o);
    }

    public <T> T fromJson(String jsonStr, Class<T> clazz) {
        return gson.fromJson(jsonStr, clazz);
    }
}
